package demo;
import java.util.*;
public class leetcode88 {
    public void merge(int[] nums1, int m, int[] nums2, int n) {
        int p1 = m - 1;
        int p2 = n - 1;
        int re = m + n - 1;
        while (p1 >= 0 && p2 >= 0 && re >= 0) {
            if (nums1[p1] > nums2[p2]){
                nums1[re] = nums1[p1];
                p1--;
            }else{
                nums1[re] = nums2[p2];
                p2--;
            }
            re--;
        }
        if (p1 < 0) {
            while (re >= 0){
                nums1[re] = nums2[p2];
                p2--;
                re--;
            }
        }
    }
    public static void main(String[] args){
        leetcode88 solution = new leetcode88();
        int[] nums1={1,2,3,0,0,0};
        int[] nums2={2,5,6};
        solution.merge(nums1,3,nums2,3);
        System.out.println(Arrays.toString(nums1));
    }
}